package 洛谷;

import java.util.Scanner;

public class 子序列和为7 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n + 1];
		int[] sum = new int[n + 1];
		int[] mp = { 0, -1, -1, -1, -1, -1, -1 };
		int ans = 0;
		for (int i = 1; i <= n; i++) {
			a[i] = sc.nextInt();
			sum[i] = (sum[i - 1] + a[i]) % 7;
			if (mp[sum[i]] != -1) {
				ans = Math.max(ans, i - mp[sum[i]]);
			} else {
				mp[sum[i]] = i;
			}
		}
		System.out.println(ans);

	}
}